package news.dao;

import news.model.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.List;

@Mapper
@Repository
public interface UserDao {
    List<User> userList(User user);

    @Update("update user set status = #{status} where id = #{id}")
    void changeStatus(Integer id, Integer status);

    @Insert("insert into user(account, password, nickname, register_time)values(#{email},#{password}," +
            "#{nickname},now())")
    void save(User user);

    @Select("select id,account,password,status,nickname from user where account=#{email} and password=#{password}")
    User userLogin(User user);


    @Select("select head_photo from user where id=1")
    String selectUrl(String account);

    @Insert("insert into comment(news_id,user_id,comment_content,comment_time,oper_time)values " +
            "(#{newsid},#{userId},#{comment},now(),now())")
    void saveComment(@Param("newsid") Integer newsid, @Param("userId") int userId, @Param("comment") String comment);

    @Select("select * from user_collection where news_id = #{newsid} and user_id = #{userId}")
    List<User> checkUserIsSC(String newsid, int userId);

    @Update("UPDATE USER SET PASSWORD =#{password},nickname=#{nickname},gender=#{gender},phone=#{phone} where id=#{userId}")
    void saveInfo(@Param("nickname") String nickname, @Param("password") String newPassword, @Param("phone") String phone,
                  @Param("gender") String gender, @Param("userId") Integer userId);

    @Select("select nickname,gender,phone from user where id=#{userId}")
    User getUserInfo(int userId);
}
